"""
@Filename:  web_driver/fanwei_app
@Author:  liukai
@Time:  2022/11/24 0024  18:00
"""
import time

import webdriver_helper
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_helper import debugger

d = webdriver_helper.get_webdriver()
d.maximize_window()
d.implicitly_wait(3)
d.get("http://47.107.116.139/fangwei/index.php")

# 立即登录
if True:
    d.find_element(By.XPATH, '//*[@id="user_head_tip"]/a[1]').click()
    d.find_element(By.XPATH, '//*[@id="login-email-address"]').send_keys("admin")
    d.find_element(By.XPATH, '//*[@id="login-password"]').send_keys('msjy123')
    d.find_element(By.XPATH, '//*[@id="ajax-login-submit"]').click()

    text = WebDriverWait(d, 10).until(lambda x: x.find_element(By.XPATH, '//*[@id="fanwe_success_box"]/table/tbody/tr/td[2]/div[2]').text.strip())
    print(text)

    if text != '成功登录':
        print("登录失败！")
    else:
        print("登陆成功")
    # 关闭弹窗
    d.find_element(By.XPATH, '//*[@id="fanwe_success_box"]/table/tbody/tr/td[2]/div[3]/input[1]').click()

    touzi = d.find_element(By.XPATH, '//*[@id="header"]/div[2]/div/ul/li[2]/a')

    ac = ActionChains(d)
    print(type(touzi.location), touzi.location)
    ac.move_by_offset(touzi.location['x'], touzi.location['y'])
    ac.perform()

    # 个人贷款
    d.find_element(By.XPATH, '//*[@id="header"]/div[2]/div/ul/li[2]/div/a[2]').click()
    # 投标
    d.find_element(By.XPATH, '/html/body/div[3]/div[1]/div[2]/div[1]/div[2]/div[2]/a').click()
    # 输入数字
    d.find_element(By.XPATH, '//*[@id="J_BIDMONEY"]').send_keys("100")
    d.find_element(By.XPATH, '//*[@id="tz_link"]').click()
    # 输入密码
    d.find_element(By.XPATH, '//*[@id="J_bid_password"]').send_keys("msjy123")

    d.find_element(By.XPATH, '//*[@id="J_bindpassword_btn"]').click()

    text = WebDriverWait(d, 10).until(
        lambda x: x.find_element(By.XPATH, '//*[@id="fanwe_success_box"]/table/tbody/tr/td[2]/div[2]').text.strip())
    print(text)

    if text != '投标成功！':
        print("投标失败！")
    else:
        print('投标成功！')

    d.find_element(By.XPATH, '//*[@id="fanwe_success_box"]/table/tbody/tr/td[2]/div[3]/input[1]').click()

    #//*[@id="fanwe_success_box"]/table/tbody/tr/td[2]/div[2]
    #

time.sleep(10)
if __name__ == '__main__':
    pass